package com.wei.tang.ui.course;

import java.util.List;

import com.wei.tang.AppContext;
import com.wei.tang.R;
import com.wei.tang.adapter.TalkInformationItemAdapter;
import com.wei.tang.base.BaseActivity;
import com.wei.tang.bean.CourseBean;
import com.wei.tang.db.JsonData;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * 教师任务界面
 *
 */
public class CourseTeacherActivity extends BaseActivity {

	private CourseTeacherActivity mySelf = this;

	@InjectView(R.id.tv_course_teacher_new)
	TextView tv_course_teacher_new;

	@InjectView(R.id.tv_course_teacher_finish)
	TextView tv_course_teacher_finish;

	@InjectView(R.id.lv_course_teacher_list)
	ListView lv_course_teacher_list;

	private List<CourseBean> courseDatas = null;
	private TalkInformationItemAdapter adapter = null;
	private int titlePosition;

	@Override
	public void initView() {
		updateTitle();
		lv_course_teacher_list.setAdapter(adapter);
		lv_course_teacher_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				if (AppContext.getInstance().getUserBean().getUser_status().equals("s")) {
					Intent intent = new Intent(mySelf, StudentWorkActivity.class);
					startActivity(intent);
				} else {
					Intent intent = new Intent(mySelf, TeacherWorkActivity.class);
					startActivity(intent);
				}
			}
		});
	}

	@Override
	public int getLayoutId() {
		return R.layout.course_teacher_activity;
	}

	@Override
	public void initData() {
		courseDatas = JsonData.getCourseBeans();
		adapter = new TalkInformationItemAdapter(mySelf, courseDatas, R.layout.talk_information_fragment_item);
		titlePosition = 1;
	}

	@Override
	protected boolean hasBackButton() {
		return true;
	}

	@Override
	protected int getActionBarTitle() {
		return R.string.course_teacher_activity;
	}

	@Override
	@OnClick({ R.id.rl_course_teacher_new, R.id.rl_course_teacher_finish })
	public void onClick(View v) {
		Intent intent = null;
		int id = v.getId();
		switch (id) {
		case R.id.rl_course_teacher_new:
			if (titlePosition == 1) {
				return;
			}
			titlePosition = 1;
			updateTitle();
			break;
		case R.id.rl_course_teacher_finish:
			if (titlePosition == 2) {
				return;
			}
			titlePosition = 2;
			updateTitle();
			break;
		}
	}

	void updateTitle() {
		switch (titlePosition) {
		case 1:
			tv_course_teacher_finish.setTextColor(mySelf.getResources().getColor(R.color.text_gray));
			tv_course_teacher_new.setTextColor(mySelf.getResources().getColor(R.color.green));
			break;
		case 2:
			tv_course_teacher_finish.setTextColor(mySelf.getResources().getColor(R.color.green));
			tv_course_teacher_new.setTextColor(mySelf.getResources().getColor(R.color.text_gray));
			break;
		}
	}
}
